package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.Announcement;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AnnouncementService {
    @Autowired
    private AnnouncementMapper mapper;

    public ResponseMessage selectAnnouncementList(){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectAnnouncementList());
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage insertAnnouncement(Announcement announcement){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertAnnouncement(announcement)>0?true:false;
        if(flag){
            message.setMessage("添加成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("添加失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage updateAnnouncement(Announcement announcement){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.updateAnnouncement(announcement)>0?true:false;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage deleteAnnouncement(Integer id){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.deleteAnnouncement(id)>0?true:false;
        if(flag){
            message.setMessage("删除成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("删除失败");
            message.setSuccess(flag);
        }
        return message;
    }
}
